package com.zhidisoft.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhidisoft.system.dao.IFunctionDao;
import com.zhidisoft.system.entity.Function;
import com.zhidisoft.system.service.IFunctionService;
import com.zhidisoft.system.vo.FunctionVO;

/**
 * 功能模块业务层实现类
 * @author Lu Jianliang
 *
 */
@Service
public class FunctionServiceImpl implements IFunctionService{
	
	@Autowired
	private IFunctionDao funcDao;

	@Override
	public String add(Function func) {
		
		return funcDao.save(func);
	}

	@Override
	public boolean update(Function func) {
		// TODO Auto-generated method stub
		return false;
	}

	
	@Override
	public List<Function> findFunctions(Integer funcType, String... roleIds) {
		return funcDao.findFunctions(funcType, roleIds);
	}

	@Override
	public List<FunctionVO> findAll() {
		List<Function> list =  funcDao.findAll();
		List<FunctionVO> functions = new ArrayList<FunctionVO>();
		//把所有的po转换为vo
		for(Function func : list){
			functions.add(FunctionVO.fromFunction(func));
		}
		
		return functions;
	}

	@Override
	public List<FunctionVO> findByRoleIds(String[] roleIds) {
		List<Function> list = funcDao.findByRoleIds(roleIds);
		List<FunctionVO> functions = new ArrayList<FunctionVO>();
		for(Function func : list){
			functions.add(FunctionVO.fromFunction(func));
		}
		return functions;
	}

	@Override
	public List<Function> findFunctions(Integer funcType) {
		
		return funcDao.findFunctions(funcType);
	}

	@Override
	public List<Function> findByParentId(Integer funcType, String parentId) {
		
		return funcDao.findByParentId(funcType, parentId);
	}


}
